/**
 * This project create for studying propose at BUPT University. You can change or reuse this project anywhere
 */
package edu.bupt.ooad.library.ui;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import edu.bupt.ooad.library.Borrow;

public class BarrowTableModel extends AbstractTableModel {

    private final static String[] COLUMNS = new String[] {"Name", "Book", "Book ID", "Time"};
    
    private List<Borrow> borrows;
    
    public BarrowTableModel(List<Borrow> borrows) {
        this.borrows = borrows == null ? new ArrayList<Borrow>() : borrows;
    }

    @Override
    public int getColumnCount() {
        return COLUMNS.length;
    }
    
    @Override
    public String getColumnName(int column) {
        return COLUMNS[column];
    }

    @Override
    public int getRowCount() {
        return borrows.size();
    }

    @Override
    public Object getValueAt(int row, int column) {
        Borrow borrow = borrows.get(row);
        
        switch (column) {
            case 0:
                return borrow.getPetron().getLastname() + " " + 
                    borrow.getPetron().getFirstname();
                
            case 1:
                return borrow.getBook().getDescription().getTitle(); 
                
            case 2:
                return borrow.getBook().getBookId();
                
            case 3:
                return borrow.getDate();

            default:
                return null;
        }
    }

}
